package com.infinitegroup.findmystuff.presenters;

import android.content.Context;

import com.infinitegroup.findmystuff.models.AccountLink;
import com.infinitegroup.findmystuff.views.LockoutView;

/**
 * Presenter for the Lockout screen/activity. Does not connect to database or any model;
 * merely contains a method for the ui and the user's benefit.
 * 
 * @author Maria
 *
 */
public class LockoutPresenter {
	LockoutView view;
	
	/***
	 * Constructor for the presenter.
	 * @param view View associated with the activity that the presenter controlls.
	 */
	public LockoutPresenter(LockoutView view){
		this.view = view;
	}
	
	/**
	 * Handles invalid input for the request form. Because we don't really do requeests, this methods
	 * is ultimately for the user.
	 * @param username Username inputed by user.
	 * @param firstname First name inputed by user.
	 * @param lastname Last name inputed by user.
	 * @param email Email inputed by user.
	 * @param phone Phone number inputed by user.
	 */
	public void sendRequest(String username, String firstname, String lastname, String email, String phone){
		AccountLink account = new AccountLink("", (Context) view);
		account.refresh(username);
		if (account.getUsername().equals("")){ // no details were fetched.
			view.displayMessage("No such user exists");
		}
		else{
			if(account.isActive() == true){
				view.displayMessage("This account is already unlocked.");
			}
			else{
				if(account.getFirstName().equals(firstname)){
					view.displayMessage("Entered information does not match account information.");
				}
				else{
					if(account.getLastName().equals(lastname)){
						view.displayMessage("Entered information does not match account information.");
					}
					else{
						if(account.getEmail().equals(email)){
							view.displayMessage("Entered information does not match account information.");
						}
						else{
							if(account.getPhone().equals(phone)){
								view.displayMessage("Entered information does not match account information.");
							}
							else{
								view.displayMessage("Request has been sent."); //essentially this is to appease the user, apparently
								view.advanceToLogin();
							}
						}
					}
				}
			}
		}
	}

}
